home *** CD-ROM | disk | FTP | other *** search
- /* put.c
- This is a set of formatting routines for use by dcmds.
- Copyright © 1988-1990 Apple Computer, Inc. All rights reserved.
-
- Modification history:
- 29Mar90 sad use dcmdScroll and dcmdDrawText
- 10Oct89 sad add PutUHexLong; change PutPStr types to unsigned char*
- 12Aug89 sad added PutDec and PutDec1
- 29Nov88 sad revised for new dcmd names.
- 5Oct88 sad written from file.c
- */
-
- #include <Types.h>
- #include <Memory.h>
-
- #include "dcmd.h"
-
- static Str255 line;
- static int linepos = 0;
-
-
- void PutLine()
- {
- dcmdScroll();
- dcmdDrawText((Ptr)line, linepos);
- linepos = 0;
- } // PutLine
-
-
- void PutChar(char c)
- {
- line[linepos++] = c;
- } // PutChar
-
-
- void PutSpace()
- {
- PutChar(' ');
- } // PutSpace
-
-
- void PutSpacesTo(int pos)
- {
- while (linepos < pos) PutSpace();
- } // PutSpacesTo
-
-
- void PutBytesTruncTo(const char* s, int len, int pos)
- {
- if (pos > linepos)
- {
- if (len <= pos - linepos)
- {
- BlockMove(s,line+linepos,len);
- linepos += len;
- while (linepos < pos) PutSpace();
- }
- else
- {
- BlockMove(s,line+linepos,pos-linepos-1);
- linepos = pos - 1;
- PutChar('…');
- }
- line[linepos] = '\0';
- }
- } // PutBytesTruncTo
-
-
- void PutBytesTo(const char* s, int len, int pos)
- {
- BlockMove(s,line+linepos,len);
- linepos += len;
- while (linepos < pos) PutSpace();
- line[linepos] = '\0';
- } // PutBytesTo
-
-
- void PutCStrTo(const char* s, int pos)
- {
- int slen = strlen(s);
- PutBytesTo(s,slen,pos);
- } // PutCStrTo
-
-
- void PutCStrTruncTo(const char* s, int pos)
- {
- int slen = strlen(s);
- PutBytesTruncTo(s,slen,pos);
- } // PutCStrTo
-
-
- void PutCStr(const char* s)
- {
- int slen = strlen(s);
- PutBytesTo(s,slen,0);
- } // PutCStr
-
-
- void PutPStrTruncTo(const unsigned char* s, int pos)
- {
- int slen = *s;
- PutBytesTruncTo((const char*)s+1,slen,pos);
- } // PutPStrTo
-
-
- void PutPStrTo(const unsigned char* s, int pos)
- {
- int slen = *s;
- PutBytesTo((const char*)s+1,slen,pos);
- } // PutPStrTo
-
-
- void PutPStr(const unsigned char* s)
- {
- int slen = *s;
- PutBytesTo((const char*)s+1,slen,0);
- } // PutPStr
-
-
- void PutUHexZTo(unsigned long i, int ndig, int pos)
- {
- unsigned long dig = i % 0x10;
- unsigned long rest = i / 0x10;
- if (rest != 0) PutUHexZTo(rest,ndig - 1,pos - 1);
- else
- {
- pos -= 1; // one for this digit
- if (ndig > 0) pos -= ndig - 1; // the leading zeros
- while (linepos < pos) PutSpace();
- while (--ndig > 0) PutChar('0');
- }
- if (dig < 10) PutChar('0' + dig);
- else PutChar('a' + (dig - 10));
- } // PutUHexZTo
-
-
- void PutUHexZ(unsigned long i, int nz)
- {
- PutUHexZTo(i,nz,0);
- } // PutUHexZ
-
-
- void PutUHexWord(unsigned short i)
- {
- PutUHexZTo(i,4,0);
- } // PutUHexWord
-
-
- void PutUHexLong(unsigned long i)
- {
- PutUHexZTo(i,8,0);
- } // PutUHexLong
-
-
- void PutUDecTo(unsigned long i, int pos)
- {
- unsigned long dig = i % 10;
- unsigned long rest = i / 10;
- if (rest != 0) PutUDecTo(rest,pos - 1);
- else
- {
- pos -= 2; // one for the '#' and one for this digit
- while (linepos < pos) PutSpace();
- PutChar('#');
- }
- PutChar('0' + dig);
- } // PutUDecTo
-
-
- void PutUDec(unsigned long i)
- {
- PutUDecTo(i,0);
- } // PutUDec
-
-
- static void PutDec1(unsigned long i, int neg)
- {
- unsigned long dig = i % 10;
- unsigned long rest = i / 10;
- if (rest != 0) PutDec1(rest, neg);
- else
- {
- PutChar('#');
- if (neg) PutChar('-');
- }
- PutChar('0' + dig);
- }
-
- void PutDec(long i)
- {
- // on a 2’s complement machine you can’t negate most negative long, but
- // it turns out that you get the right answer anyway
- if (i < 0) PutDec1(-i,1); // *** can’t negate most negative number!
- else
- PutDec1(i,0);
- } // PutDec
-
-
- void PutOSType(unsigned long typ)
- {
- PutChar((typ>>24) & 0xff);
- PutChar((typ>>16) & 0xff);
- PutChar((typ>>8) & 0xff);
- PutChar(typ & 0xff);
- } // PutOSType
-